import requests
import re



headers={
    'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36'
}


ur='https://baidurank.aizhan.com/baidu/ugainian.com/'
htm=(requests.get(ur,headers=headers).text)
#print(html)

ymnrze=r'<div class="baidurank-pager">(.+?)<div class="baidurank-content box">'
ymnr=re.findall(ymnrze,htm,re.S)
print(ymnr)
ymze=r'href="https://baidurank.aizhan.com/baidu/.+?/-1/0/(.+?)/position/1/"'
ym=re.findall(ymze,str(ymnr),re.S)
print(ym)
ymsj=[]
ymsj.append(ym)
for i in ymsj:
    print(i[-1])
    x=int(i[-1])

for n in range(1,x+1):
    url=f'https://baidurank.aizhan.com/baidu/ugainian.com/-1/0/{n}/position/1/'
    print(url)
    html= (requests.get(url, headers=headers).text)
#ze=r'''<td class="title">
#<a class="gray" rel="nofollow" target="_blank" href="(.+?)" title=".+?">
#	(.+?)							</a>
#</td>'''
    ze=r'''<tr>
                                                    <td class="title">
                                <a class="gray" rel="nofollow" target="_blank" href="(.+?)" title="(.+?)">
                                    .+?							</a>
                            </td>
                            <td class="center">
                                <span class="blue">
                                                                    (.+?)
                                                                </span>
                            </td>
                            <td class="center">
                                <a class="gray" rel="nofollow" target="_blank" href=".+?">
                                    (.+?)							</a>
                            </td>
                            <td class="center">
                                <a class="gray" target="_blank" href=".+?">
                                    (.+?)							</a>
                            </td>
                            <td class="owner">
                                <a name="baiduLink" rel="nofollow" target="_blank" href="(.+?)" class="gray" title="(.+?)">
                                    .+?							</a>
                            </td>
                        </tr>'''
    sj=re.findall(ze,html,re.S)
    print(sj)
    for jg in sj:
        print(jg[1])
        print(jg[3])
        print(jg[4])